macro AddCurFile2Proj()
{
	hbuf=GetCurrentBuf()
	filename=GetBufName(hBuf)
	if(True==AddFileToProj(GetCurrentProj(), filename)){
		Msg("File:@filename@ has been added to project!")
	}
	else{
		Msg("can't add @filename@ to project!")
	}
}



macro AddSourceFiles2Proj()
{
	hbuf=GetCurrentBuf()
	hproj=GetCurrentProj()
	path=GetBufName(hbuf)
	path=GetFilePath(path)
//DbgMsg("path:", path)

	addNum="0"
	bufaddFile=NewBuf("")
	AppendBufLine(bufaddFile, "the files add to project:")

	addFaildNum="0"
	bufaddFaild=NewBuf("")
	AppendBufLine(bufaddFaild, "the files can't add to project:")

	srcPatten="^\w*[ARM_]*SOURCES="
//DbgMsg("srcPatten:", srcPatten)
	flPatten="\\w*\\([a-zA-Z_0-9\\.\\\\]+\\)"
//DbgMsg("flPatten:", flPatten)

	lnSrcStart=0
	while(1){
		selSrc=SearchInBuf (hbuf, srcPatten, lnSrcStart, 0, 0, 1, 0)
//DbgMsg("source find:", selSrc)
		if(""==selSrc){
			break
		}
		
		lnFlileStart=selSrc.lnLast
		chStart=selSrc.ichLim
		hbufSrch=NewBuf("")
		while(1){
			ClearBuf(hbufSrch)
			selFile=SearchInBufEx (hbuf, flPatten, lnFlileStart, chStart, 0, 1, 0, hbufSrch, 0)
//DbgMsg("selFile:", selFile)
			// the valid source file must in the same line or the immediat line
			if(""==selFile){
				break
			}
			if(selFile.lnFirst!=lnFlileStart){
				break
			}
			lnFlileStart=selFile.lnLast+1	// adjust the serarch start line

			chStart=0

			file=GetBufLine(hbufSrch, 1)
			if("\\"==file){
				continue
			}

			file=cat(path, file)
//DbgMsg("file:", file)
			if(True==AddFileToProj(hproj, file)){
				AppendBufLine(bufaddFile, file)
				addNum=addNum+1
			}
			else{
				AppendBufLine(bufaddFaild, file)
				addFaildNum=addFaildNum+1
//DbgMsg("file add faild:", file)
			}
		}

		CloseBuf(hbufSrch)
		lnSrcStart=selSrc.lnLast+1	// adjust the serarch start line
	}

	// display the result
	if("0"!=addNum){
		// add a empty line for safe
		AppendBufLine(bufaddFile, "")

		// init select record
		sel=""
		sel.lnFirst=0
		sel.lnLast=addNum+1
		sel.ichFirst=0
		sel.ichLim=0
		
		Msg(GetSelectStr(bufaddFile, sel))
		CloseBuf(bufaddFile)
	}

	if("0"!=addFaildNum){
		// add a empty line for safe
		AppendBufLine(bufaddFaild, "")

		// init select record
		sel=""
		sel.lnFirst=0
		sel.lnLast=addFaildNum+1
		sel.ichFirst=0
		sel.ichLim=0
//DbgMsg("sel:", sel)
		
		Msg(GetSelectStr(bufaddFaild, sel))
		SetCurrentWnd(NewWnd(bufaddFaild))
	}
	else {
		CloseBuf(bufaddFaild)
	}
}

macro GetFilePath(filePath)
{
//DbgMsg("filePath:", filePath)
	i=strlen(filePath)
	while(0!=i){
		if("\\"==filePath[i-1]){
			break;
		}
		i=i-1
	}
	path=strtrunc(filePath, i)
//DbgMsg("path:", path)

	return path
}

macro AddFiles2Proj()
{
	hbufToAdd=GetCurrentBuf()
	hproj=GetCurrentProj()
	srcPatten="^\\w*\\(.+\\)\\w*$"
	hbufSrcRst=NewBuf("")
	hbufAddedFile=NewBuf("Added file")
	AppendBufLine(hbufAddedFile, "Added file:")
	AppendBufLine(hbufAddedFile, "")
	
	addNum="0"
	lnSrcStart=0
	while(1){
		ClearBuf(hbufSrcRst)
		selSrc=SearchInBufEx (hbufToAdd, srcPatten, lnSrcStart, 0, 0, 1, 0, hbufSrcRst, 0)
		if(""==selSrc){
			break
		}

		lnSrcStart=selSrc.lnLast+1
		fileToAdd=GetBufLine(hbufSrcRst, 1)

// it seems that should use full path!!!
		if(True==AddFileToProj(hproj, fileToAdd)){
			AppendBufLine(hbufAddedFile, "    @fileToAdd@")
			addNum=addNum+1
		}
	}
	
	CloseBuf(hbufSrcRst)

	AppendBufLine(hbufAddedFile, "")
	AppendBufLine(hbufAddedFile, "Totale number added: @addNum@")
	SetCurrentWnd(NewWnd(hbufAddedFile))

}


